/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-02-24 13:09:49
 * @LastEditTime: 2024-06-22 19:18:42
 * @FilePath: /nest_study/web/src/components/authRouter/index.tsx
 */
import { getCache } from "@/utils/storage"
import { Navigate } from "react-router-dom";
import { syncRouters } from '@/router'
import { matchRoute } from "@/router/match";

const AuthRouter = (props: { children: JSX.Element }) => {
    let token = getCache('token');
    let { pathname } = location;
    let currentRoute = matchRoute(pathname, syncRouters());
    if (token || currentRoute?.meta?.isAuth) {
        return props.children;
    } else {
        return <Navigate to="/login" />
    }
}

export default AuthRouter